const initialState = {
  arr:[ ],
  arrcopy:[],
  allchecked:false
}

export default (state = initialState, { type, payload,index}) => {
 console.log(index,"index");
switch (type) {

case "getlist":
   let newARR = [...state.arr]
   let newARRCOPY =  [...state.arrcopy]
   newARR = payload
   newARRCOPY= payload
  return { ...state, arr:newARR ,arrcopy:newARRCOPY}
case "radioFn" :
     let newallchecked = state.allchecked
     let copynewarr = JSON.parse(JSON.stringify(state.arrcopy))
     copynewarr.forEach( item => {
          item.answer.forEach(element => {
               if (element.id ===  payload) {
                   element.checked = true
                   
               }
          });
     });
     // 只要点过就说明当前项的题做过
     copynewarr.forEach( item => {
      item.answer.forEach(element => {
           if (element.checked) {
              item.flag = true
           }
      });
    });
    // 判断做对对没做对
    copynewarr.forEach( item => {
      item.answer.forEach(element => {
           if (index === item.rightkey) {
              item.zhen = true
           }
      });
    });
    // 判断有没有做完
    newallchecked =  copynewarr.every(item=>item.flag)
     
    return {
        ...state,
        arr:copynewarr,
        arrcopy:copynewarr,
        allchecked:newallchecked
    }
default:
  return state
}
}
